<?php

/**
 * Created by PhpStorm.
 * User: FDG367
 * Date: 2017/9/18
 * Time: 12:54
 */

namespace api\models;

use Yii;

/**
 * This is the model class for table "j_line_goods_sync".
 *
 * @property integer $id
 * @property string $sku
 * @property string $goods_name_cn
 * @property string $goods_name_other
 * @property integer $country_id
 * @property string $country_name
 * @property integer $brand_id
 * @property string $brand_name
 * @property string $unit
 * @property string $sale_price
 * @property string $market_price
 * @property integer $category
 * @property integer $spec
 * @property string $spec_val
 * @property integer $spec_color
 * @property string $spec_color_val
 * @property string $creator
 * @property string $create_time
 * @property string $editor
 * @property string $editor_time
 */
class LineGoodsSync extends \common\models\LineGoodsSync
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sku', 'goods_name_cn', 'brand_name', 'unit', 'genre_type', 'spec_val', 'spec_color_val', 'creator',  'editor'], 'required'],
            [['sale_price', 'market_price'], 'number'],
            [['genre_type'], 'integer'],
            [['create_time', 'editor_time'], 'safe'],
            [['sku', 'goods_name_cn', 'country_name', 'brand_name', 'spec_val', 'spec_color_val'], 'string', 'max' => 100],
            [['unit'], 'string', 'max' => 20],
            [['creator', 'editor'], 'string', 'max' => 60],
            [['sku'], 'unique'],
        ];
    }

    /**
     * @return bool|void
     * @param 保存之前处理参数
     */
    public function beforeSave($insert){
        if($insert){
            $this->editor_time  = date('Y-m-d H:i:s');
            $this->create_time  = date('Y-m-d H:i:s');
        }
        //更新
        $this->editor_time  = date('Y-m-d H:i:s');
        return true;
    }
}
